import { observable, action,computed,autorun} from 'mobx';

class TodoStore{
    id = Math.random()*1000
    @observable name = 'abc'
    @observable age = 10
    @action
    setName = () => {
        this.name = "haohaizi"
    }

    @computed
    get unfinshedName(){
        return this.name.length > 4
    }

    getUnfinshedName(){
        return this.name.length > 4
    }
}



const todoStore = new TodoStore()


//为什么只改变一次，后面不满足条件才触发，
autorun(() => {
    console.log('computed:', todoStore.unfinshedName)
})

autorun(() => {
    console.log('getter:', todoStore.getUnfinshedName())
})


todoStore.name = "haohaizi"

setTimeout(()=>{
    todoStore.name = "i"
},3000)



export default todoStore


